//package com.ghxxzx.dagl.utils;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import org.apache.commons.dbutils.BasicRowProcessor;
//import org.apache.commons.dbutils.BeanProcessor;
//import org.apache.commons.dbutils.GenerousBeanProcessor;
//import org.apache.commons.dbutils.QueryRunner;
//import org.apache.commons.dbutils.handlers.BeanHandler;
//import org.apache.commons.dbutils.handlers.BeanListHandler;
//import org.apache.commons.dbutils.handlers.ScalarHandler;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Configuration;
//
//import javax.sql.DataSource;
//import java.math.BigDecimal;
//import java.sql.SQLException;
//import java.util.List;
//public class JdbcUtils {
//    private static QueryRunner queryRunner = null;
//    static {
//        DruidDataSource druidDataSource = new DruidDataSource();
//        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
//        druidDataSource.setMaxActive(20);
//        druidDataSource.setMinIdle(20);
//        druidDataSource.setUrl("jdbc:mysql://49.235.147.200:3307/da?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true");
//        druidDataSource.setUsername("root");
//        druidDataSource.setPassword("root");
//        queryRunner = new QueryRunner(druidDataSource);
//    }
//    public static <T> List<T> queryList(String sql, Class<T> t) throws SQLException {
////        QueryRunner queryRu·nner = new QueryRunner(dataSource);
//        BeanProcessor processor = new GenerousBeanProcessor();
//        BasicRowProcessor basicRowProcessor = new BasicRowProcessor(processor);
//        List<T> list = queryRunner.query(sql, new BeanListHandler<>(t, basicRowProcessor));
//        return list;
//    }
//    public static Long getLongCount(String sql) throws SQLException {
//        try {
//            BigDecimal bigDecimal = queryRunner.query(sql, new ScalarHandler<BigDecimal>());
//            long l = bigDecimal.longValue();
//            return l;
//        } catch (Exception e) {
//            Long as = queryRunner.query(sql, new ScalarHandler<Long>());
//            if (as==null){
//                as=0l;
//            }
//            return as;
//        }
//    }
//    public static <T> T queryOne(String sql, Class<T> t) throws SQLException {
////        QueryRunner queryRunner = new QueryRunner(dataSource);
//        BeanProcessor processor = new GenerousBeanProcessor();
//        BasicRowProcessor basicRowProcessor = new BasicRowProcessor(processor);
//        T query = queryRunner.query(sql, new BeanHandler<>(t, basicRowProcessor));
//        return query;
//    }
//}
